<?php
/**
 * Samble Session handler class
 * @author Lim afriyadi
 * @license GNU/GPL v.3
 * @version pre-alpha
 * @package Samble
 * @subpackage session
 */
class Session
 {
     /**
      * Session class singleton instance.
      * @var object
      */
     private static $o_Instance;

     private function session()
     {
        $this->a_Sessions = $_SESSION;
     }
     /**
      * Initialize and grab this class instance.
      * @return object
      */
     public static function getInstance()
     {
         session_start();
         if( !self::$o_Instance )
         {
             self::$o_Instance = new session();
         }
         return self::$o_Instance;
     }
     /**
      * Register and save a session key.
      *
      * @param string $s_Session_Name
      * @param object $o_Session
      * @return boolean
      */
     public function regSession( $s_Session_Name="",$o_Session="" )
     {
        session_start();
        if( $s_Session_Name != "" && $o_Session != "" )
        {
            $_SESSION[$s_Session_Name] = $o_Session;
            return true;
        }
        return false;
     }
     /**
      * Remove a registered session identified by its key.
      * @param string $s_Session_Name
      * @return boolean
      */
     public function unregSession( $s_Session_Name="" )
     {
         session_start();
         if( isset( $_SESSION[$s_Session_Name] ) )
         {
            unset( $_SESSION[$s_Session_Name] );
            $_SESSION = array_values( $_SESSION );
            return true;
         }
         return false;
     }
     /**
      * Get a session value by its key.
      * @param string $s_Session_Name
      * @return object || false
      */
     public function getSessionVal( $s_Session_Name="" )
     {
        session_start();
        if( isset( $_SESSION[$s_Session_Name] ) )
        {
            return $_SESSION[$s_Session_Name];
        }
        return false;
     }
     /**
      * Get a session key by its value.
      * @param object $o_SessionValue
      * @return string || false
      */
     public function getSessionKey( $o_SessionValue="" )
     {
         session_start();
         $s_Key = array_search( $o_SessionValue, $_SESSION, true );
         if( $s_Key )
         {
             return $s_Key;
         }
         return false;
     }
     /**
      * Get a session key by its value.
      * @param object $o_SessionValue
      * @return string || false
      */
     public function clearSession()
     {
         $_SESSION=array();
         session_destroy();
     }
 }
?>
